#include <iostream>
#include <unistd.h>
#include <memory>
#include "Socket.hpp"

// ./client serverip serverport
int main(int argc, char* argv[])
{
    if(argc != 3)
    {
        std::cout << "Usage: " << argv[0] << " serverip serverport" << std::endl;
        return 0;
    }
    std::string serverip = argv[1];
    uint16_t serverport = std::stoi(argv[2]);

    std::unique_ptr<TcpSocket> tsvr(new TcpSocket());
    if(!tsvr->BuildConnectSocketMethod(serverip, serverport))
    {
        std::cerr << "connect " << serverip << ":" << serverport << " failed" << std::endl;
        return 0;
    }
    std::cout << "connect " << serverip << ":" << serverport << " success" << std::endl;

    std::string message = "a";
    char n = 'b';
    while(true)
    {
        tsvr->Send(message);
        message.push_back(n++);
        sleep(1);
    }

    tsvr->CloseSocket();
    return 0;
}